package com.huilunyingshi.videoconsumer.controller;

import com.huilunyingshi.videoapi.service.TAnimeService;
import com.hullunyingshi.until.ControllerResult;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

@Slf4j
@Scope("prototype")
@RestController
@RequestMapping("/Anime")
public class AnimeController {
    private final Logger logger = LoggerFactory.getLogger(AnimeController.class);

    @Autowired
    private TAnimeService tAnimeService;

    /**
     * 分页查询动漫列表
     *
     * @param keyword
     * @param curPage
     * @return
     * @throws ParseException
     */
    @ApiOperation(value = "分页查询动漫列表", notes = "分页查询动漫列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keyword", value = "动漫名", paramType = "query", dataType = "String", required = false),
            @ApiImplicitParam(name = "curPage", value = "当前页", paramType = "query", dataType = "int", required = false)
    })
    @GetMapping ("getAnimeList")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "查询成功", response = ControllerResult.class),
            @ApiResponse(code = 400, message = "查询失败", response = String.class),
            @ApiResponse(code = 500, message = "(服务器内部错误)服务器遇到错误，无法完成请求 ", response = String.class),
    })
    public ControllerResult getAnimeList( String keyword,
                                       Integer curPage
    ) throws ParseException {

        logger.info("#################### AnimeController. /Anime/getAnimeList" + keyword+"##"+curPage+"#######");
        try {
            return tAnimeService.getAnimeList(keyword,curPage);
        } catch (Exception e) {
            logger.info("#################### error 500 /Anime/getAnimeList" + e.getStackTrace());
            return new ControllerResult("500", "服务器错误", null);
        }
    }

    @ApiOperation(value = "查询动漫", notes = "查询动漫")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "动漫id", paramType = "query", dataType = "long", required = false),

    })
    @GetMapping ("getAnime")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "查询成功", response = ControllerResult.class),
            @ApiResponse(code = 400, message = "查询失败", response = String.class),
            @ApiResponse(code = 500, message = "(服务器内部错误)服务器遇到错误，无法完成请求 ", response = String.class),
    })
    public ControllerResult getAnime(Long id) throws ParseException{
        logger.info("#################### AnimeController. /Anime/getAnime" + id+"#######");
        try {
            return tAnimeService.getAnime(id);
        } catch (Exception e) {
            logger.info("#################### error 500 /Anime/getAnime" + e.getStackTrace());
            return new ControllerResult("500", "服务器错误", null);
        }

    }

    @ApiOperation(value = "查询类型动漫", notes = "查询类型动漫")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lid", value = "动漫类型id", paramType = "query", dataType = "long", required = false),
            @ApiImplicitParam(name = "curPage", value = "当前页", paramType = "query", dataType = "int", required = false)
    })
    @GetMapping ("getAnimeTypeList")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "查询成功", response = ControllerResult.class),
            @ApiResponse(code = 400, message = "查询失败", response = String.class),
            @ApiResponse(code = 500, message = "(服务器内部错误)服务器遇到错误，无法完成请求 ", response = String.class),
    })
    public ControllerResult getAnimeTypeList(Long lid,  Integer curPage) throws ParseException{
        try {
            return tAnimeService.getAnimeTypeList(lid,curPage);
        }catch (Exception e){
            logger.info("#################### error 500 /Film/getFilmTypeList" + e.getStackTrace());
            return new ControllerResult("500", "服务器错误", null);
        }
    }



}
